"""
题目：
再一个很长很长的数组中， 如何快速找到第二大的元素。
注意时间复杂度和空间复杂度

输入: nums = [1, 2, 3, 4]
输出: 3

思路： 利用冒泡排序的思路，或者是选择排序的思路。 
遍历一次就可以找到最大值，那么我们只需要找另一个变量记录最小值
"""

# nums = [1, 2, 3, 4]
nums = [100,-74,48,-20,2,10,-84,-5,-9,11,-24,-91,2,-71,64,63,80,28,-30,-58,-11,-44,-87,-22,54,-74,-10,-55,-28,-46,29,10,50,-72,34,26,25,8,51,13,30,35,-8,50,65,-6,16,-2,21,-78,35,-13,14,23,-3,26,-90,86,25,-56,91,-13,92,-25,37,57,-20,-69,98,95,45,47,29,86,-28,73,-44,-46,65,-84,-96,-24,-12,72,-68,93,57,92,52,-45,-2,85,-63,56,55,12,-85,77,-39]

def getNum2(nums: list):
    first = second = -1*1000000000000
    for i in nums:
        if i > first: 
            second = first
            first = i
        elif i > second: 
            second = i
    
    return second

rst = getNum2(nums)
print(rst)